<?php
$this->pageTitle=Yii::app()->name . ' - '.UserModule::t("Registration");
$baseUrl = Yii::app()->baseUrl; 
$cs=Yii::app()->getClientScript();
$cs->registerScriptFile('http://maps.google.com/maps/api/js?sensor=false', CClientScript::POS_HEAD);
$cs->registerScriptFile($baseUrl.'/scripts/account_type_handler.js', CClientScript::POS_END);

$this->breadcrumbs=array(
	UserModule::t("Registration"),
);
?>

<?php  
  $baseUrl = Yii::app()->baseUrl; 
  $cs = Yii::app()->getClientScript();
  $cs->registerScriptFile($baseUrl.'/scripts/google_map_handler.js', CClientScript::POS_END);
?>

<h1><?php echo UserModule::t("Registration"); ?></h1>

<?php if(Yii::app()->user->hasFlash('registration')): ?>
<div class="success">
<?php echo Yii::app()->user->getFlash('registration'); ?>
</div>
<?php else: ?>

<div class="form">
<?php $form=$this->beginWidget('UActiveForm', array(
	'id'=>'registration-form',
	'enableAjaxValidation'=>true,
	'disableAjaxValidationAttributes'=>array('RegistrationForm_verifyCode'),
	'htmlOptions' => array('enctype'=>'multipart/form-data'),
)); ?>

	<p class="note"><?php echo UserModule::t('Fields with <span class="required">*</span> are required.'); ?></p>
	
	<?php echo $form->errorSummary(array($model,$profile)); ?>
	
	<div class="row">
	<?php echo $form->labelEx($model,'username'); ?>
	<?php echo $form->textField($model,'username'); ?>
	<?php echo $form->error($model,'username'); ?>
	</div>
	
	<div class="row">
	<?php echo $form->labelEx($model,'password'); ?>
	<?php echo $form->passwordField($model,'password'); ?>
	<?php echo $form->error($model,'password'); ?>
	<p class="hint">
	<?php echo UserModule::t("Minimal password length 4 symbols."); ?>
	</p>
	</div>
	<div class="row">
	<?php echo $form->labelEx($model,'verifyPassword'); ?>
	<?php echo $form->passwordField($model,'verifyPassword'); ?>
	<?php echo $form->error($model,'verifyPassword'); ?>
	</div>
	<div id="account_type" class="row">
    <input type="radio" name="account_type_ctrl" id="radio_firma"><label for="radio_firma" class="inline">Firma</label>
    <input type="radio" name="account_type_ctrl" id="radio_osoba" checked="checked"><label for="radio_osoba" class="inline">Osoba prywatna</label>
  </div>
	<div class="row">
	<?php echo $form->labelEx($model,'email'); ?>
	<?php echo $form->textField($model,'email'); ?>
	<?php echo $form->error($model,'email'); ?>
	</div>

<?php 
    $profileFields=$profile->getFields();
    if ($profileFields) {
      foreach($profileFields as $field) {
      ?>
  <?php 
    $row_class = 'row';
    $row_class .= $profile->try_get_class_for_hidden_field($field);
    $row_class .= $profile->try_get_class_for_company_field($field);
    $row_class .= $profile->try_get_class_for_only_private_field($field);
  ?>
  <div id="<?php echo $field->varname; ?>" class="<?php echo $row_class; ?>">
    <?php echo $form->labelEx($profile,$field->varname);
    
    if ($field->widgetEdit($profile)) {
      echo $field->widgetEdit($profile);
    } elseif ($field->range) {
      echo $form->dropDownList($profile,$field->varname,Profile::range($field->range));
    } elseif ($field->field_type=="TEXT") {
      echo $form->textArea($profile,$field->varname,array('rows'=>6, 'cols'=>50));
    } elseif ($field->field_type=="HIDDEN_VARCHAR") {  
      echo $form->textField($profile,$field->varname,array('size'=>60,'maxlength'=>(($field->field_size)?$field->field_size:255)));
    } else {
      echo $form->textField($profile,$field->varname,array('size'=>60,'maxlength'=>(($field->field_size)?$field->field_size:255)));
    }
    echo $form->error($profile,$field->varname); ?>
  </div>	
      <?php
      }
    }
?>



  <?php // google maps ?>
  <div class="row">
    <input type="checkbox" id="Profile_show_me_on_map" name="Profile[show_me_on_map]" checked="checked" /><label for="Profile_show_me_on_map" class="inline">Pokazuj moją lokalizację na mapie</label>
    <input type="text" id="latlng" name="latlng" value="input hidden" />
  </div>
  <div class="map_section">
    <div id="registration_map"><!-- . --></div>
  </div>

	<?php if (UserModule::doCaptcha('registration')): ?>
	<div class="row">
		<?php echo $form->labelEx($model,'verifyCode'); ?>
		
		<?php $this->widget('CCaptcha'); ?>
		<?php echo $form->textField($model,'verifyCode'); ?>
		<?php echo $form->error($model,'verifyCode'); ?>
		
		<p class="hint"><?php echo UserModule::t("Please enter the letters as they are shown in the image above."); ?>
		<br/><?php echo UserModule::t("Letters are not case-sensitive."); ?></p>
	</div>
	<?php endif; ?>
	
	<div class="row submit">
		<?php echo CHtml::submitButton(UserModule::t("Register")); ?>
	</div>

<?php $this->endWidget(); ?>
</div><!-- form -->
<?php endif; ?>

<script type='text/javascript'>
  jQuery(document).ready(function(jQuery){
    initialize_map(document.getElementById("registration_map"));
    var radio_firma = jQuery('#radio_firma');
    var radio_osoba = jQuery('#radio_osoba');
	
	
    var get_account_type = function() {

      if (radio_osoba.attr('checked')) {
		return 0;
      }

      if (radio_firma.attr('checked')) {
        return 1;
      }
      
    }

    var form_fields_data = <?php echo CJavaScript::encode($profile->get_fields_js_data());?>;
    var account_type = <?php echo $profile->get_account_type();?>;
    rearrange_fields_by_type(form_fields_data, account_type);
   
    radio_osoba.change(function(){
      rearrange_fields_by_type(form_fields_data, get_account_type());
    });

    radio_firma.change(function(){
      rearrange_fields_by_type(form_fields_data, get_account_type());
    });
  });
</script>
